import { Animation, AnimationClip, Component, Node, _decorator } from 'cc';
import { GameEventType } from "../Event/EnumDefine";
import { EventManager } from "../Event/EventManager";
const { ccclass, property } = _decorator;

/** 主角获取到道具后，发光效果 */
@ccclass('FusionEffect')
export class FusionEffect extends Component {
  @property(Node) // 绑定包含 Animation 组件的节点
  private targetNode: Node = null;

  private animation: Animation | null = null;

  protected onLoad(): void {
    EventManager.instance.registerEvent(GameEventType.Player_Glow_Effect, this.onPlay, this);
      
  }

  onPlay() {
    // 检查目标节点是否存在
    if (!this.targetNode) {
      console.error('Target node is not assigned in the inspector!');
      return;
    }

    this.targetNode.active = true;

    // 获取 Animation 组件
    this.animation = this.targetNode.getComponent(Animation);

    // 播放动画
    if (this.animation) {
      // 设置为循环播放
      this.animation.defaultClip.wrapMode = AnimationClip.WrapMode.Loop;
      this.animation.play('fusion_animation');
      // console.warn('动画播放');
    } else {
      console.error(
        'Animation component not found on the target node! Please add an Animation component to:',
        this.targetNode.name,
      );
    }
  }

  update(deltaTime: number) {}
}
